/*
 * Copyright (C) 2023 Kevin Buzeau
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.buzbuz.smartautoclicker.feature.tutorial.domain.model.game

import android.graphics.PointF
import androidx.annotation.StringRes
import com.buzbuz.smartautoclicker.feature.tutorial.data.game.TutorialGameData
import com.buzbuz.smartautoclicker.feature.tutorial.data.game.TutorialGameStateData
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.map

data class TutorialGame(
    @StringRes val instructionsResId: Int,
    val highScore: Int,
    val state: Flow<TutorialGameState>,
    val targets: StateFlow<Map<TutorialGameTargetType, PointF>>,
)

data class TutorialGameState(
    val isStarted: Boolean,
    val isWon: Boolean?,
    val timeLeft: Int,
    val score: Int,
)

internal fun TutorialGameData.toDomain(): TutorialGame =
    TutorialGame(
        instructionsResId = instructionsResId,
        highScore = highScore,
        state = gameState.map { it.toDomain() },
        targets = targets,
    )

private fun TutorialGameStateData.toDomain(): TutorialGameState =
    TutorialGameState(
        isStarted = isStarted,
        isWon = isWon,
        timeLeft = timeLeft,
        score = score,
    )